﻿using CapturePackage.Model;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Text.RegularExpressions;
using System.Threading.Tasks;

namespace CapturePackage
{
    public class ImageMigration
    {
        //正则表达式抓包
        public ImageMigration()
        {

        }

        /// <summary>
        /// image 匹配图片
        /// </summary>
        /// <param name="Context"></param>
        /// <param name="TextMigrationId"></param>
        public static void ImageMigrationCache(string Context, int TextMigrationId, string AnyShareWikiId, string dateTime)
        {
            try
            {
                string pattern = "<img[^>]+?class=\"confluence-embedded-image[^>]+?\"[^>]+?src=\"\\/download\\/attachments[^>]+?\"[^>]+?(alt=\"\"|)>";
                MatchCollection matches = Regex.Matches(Context, pattern);
                List<imagemigration> images = new List<imagemigration>();
                foreach (Match item in matches)
                {
                    images.Add(new imagemigration()
                    {
                        TextMigrationId = TextMigrationId,
                        ConfluenceImageUrl = item.Value,
                        IsMigration = 0,
                        IsDelete = 0,
                        AnyShareWikiId = AnyShareWikiId,
                        DateTime = dateTime
                    });
                }
                //匹配附件图片路径
                pattern = "<a[\\w\\W]+?class=\"confluence-embedded-file\"[\\w\\W]+?href=\"[\\w\\W]+?\"[\\w\\W]+?<img[\\w\\W]+?</a>";
                MatchCollection match2 = Regex.Matches(Context, pattern);
                foreach (Match item in match2)
                {
                    images.Add(new imagemigration()
                    {
                        TextMigrationId = TextMigrationId,
                        ConfluenceImageUrl = item.Value,
                        IsMigration = 0,
                        IsDelete = 0,
                        AnyShareWikiId = AnyShareWikiId,
                        DateTime = dateTime
                    });
                }
            }
            catch (Exception ex)
            {
            }
        }

        /// <summary>
        /// 
        /// </summary>
        public static void ImageReplace(string AnyShareWikiId)
        {

        }
    }
}
